package com.yunxi.service.dubboService.impl;

import cn.jiguang.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.yunxi.freeze.pojo.AmountFreezeVO;
import com.yunxi.freeze.service.AmountFreezeDubboService;
import com.yunxi.model.freeze.AmountFreeze;
import com.yunxi.order.pojo.PartnerFreezeAmountReqVO;
import com.yunxi.service.localService.AmountFreezeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2019-07-09
 */
public class AmountFreezeDubboServiceImpl implements AmountFreezeDubboService {
    private static final Logger logger = LoggerFactory.getLogger(AmountFreezeDubboServiceImpl.class);
    @Autowired
    @Qualifier(value = "amountFreezeServiceImpl")
    AmountFreezeService amountFreezeService;


    @Override
    public AmountFreezeVO getById(String id) throws InvocationTargetException, IllegalAccessException {
    AmountFreeze amountFreeze = amountFreezeService.getById(id);
    AmountFreezeVO amountFreezeVO = new AmountFreezeVO();
        BeanUtils.copyProperties(amountFreeze,amountFreezeVO);
        return amountFreezeVO;
    }

    @Override
    public void saveOrUpdate(AmountFreezeVO amountFreezeVO) throws InvocationTargetException, IllegalAccessException {

        if(StringUtils.isEmpty(amountFreezeVO.getFreezeId())){//如果是新增,则需判断是否重复,重复数据不能添加,
            QueryWrapper qw = new QueryWrapper();
            qw.eq("PARTNER_CODE",amountFreezeVO.getPartnerCode());
            qw.eq("CATALOG_CODE",amountFreezeVO.getCatalogCode());
            qw.eq("ORDER_TYPE",amountFreezeVO.getOrderType());
            AmountFreeze qAmountFreeze = amountFreezeService.getOne(qw);
            if(qAmountFreeze != null){
                logger.debug("重复添加数据,返回");
                return;
            }
        }

        AmountFreeze amountFreeze = new AmountFreeze();
        BeanUtils.copyProperties(amountFreezeVO,amountFreeze);
        amountFreezeService.saveOrUpdate(amountFreeze);
    }

    @Override
    public void removeById(String id) {
    amountFreezeService.removeById(id);
    }

    @Override
    public PageInfo<AmountFreezeVO> findPageByVO(AmountFreezeVO amountFreezeVO, Integer pageNum, Integer pageSize) throws InvocationTargetException, IllegalAccessException {
        PageInfo<AmountFreezeVO> pageInfo = amountFreezeService.pageByVo(amountFreezeVO,pageNum,pageSize);
        return pageInfo;
    }

    @Override
    public void removeByListVo(List<AmountFreezeVO> amountFreezeVOList) throws IllegalAccessException, InvocationTargetException, InstantiationException {
        amountFreezeService.removeByListVo(amountFreezeVOList);
    }

    @Override
    public List listByVo(AmountFreezeVO amountFreezeVO) {
      return amountFreezeService.listByVo(amountFreezeVO);
    }


    /**
     * 查询渠道商冻结资金
     * @param
     * @return
     */
    @Override
    public PageInfo listPartnerFreezeAmount(PartnerFreezeAmountReqVO reqVO,Integer pageNum, Integer pageSize) {
        return amountFreezeService.listPartnerFreezeAmount(reqVO,pageNum,pageSize);
    }


    /**
     * 查询资金变动明细
     * @param reqVO
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo listPartnerFreezeAmountDetail(PartnerFreezeAmountReqVO reqVO, Integer pageNum, Integer pageSize) {
        return amountFreezeService.listPartnerFreezeAmountDetail(reqVO,pageNum,pageSize);
    }
}
